package com.yingside.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yingside.system.mapper.RoleMenuMapper;
import com.yingside.system.model.Role;
import com.yingside.system.mapper.RoleMapper;
import com.yingside.system.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yingside
 * @since 2020-12-30
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private RoleMenuMapper roleMenuMapper;

    @Override
    public Page<Role> selectAllByQuery(Integer page, Integer limit, Role roleQuery) {
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        if(roleQuery != null){
            queryWrapper.like(
                    roleQuery.getRoleName() != null && !roleQuery.equals(""),
                    "role_name",
                            roleQuery.getRoleName());
        }
        Page<Role> pages = new Page<>((page - 1),limit);
        Page<Role> rolePage = roleMapper.selectPage(pages,queryWrapper);
        return rolePage;
    }

    @Override
    public Integer[] getMenusByRoleId(Integer roleId) {
        return roleMenuMapper.getMenusByRoleId(roleId);
    }
}
